/**
 * $Id: Employee.java 80 2012-12-13 16:33:00Z Denis.Skalsky@gmail.com $
 */
package com.globallogic.skalskyy.javabasic.valstaff;

/**
* Employee stores common info.
* @author $Author: Denis.Skalsky@gmail.com $
* @version $Revision: 80 $
*/
/**
 * @author Name
 *
 */
abstract public class Employee{

	
	/** Employee's id */
	private int id = -1;
	
	/** Employee's first name */
	private String firstName;
	
	/** Employee's second name */
	private String secondName;
	
	/** Employee's position */
	private String position;
	
	/** Employee's date of birth */
	private String dateOfBirth;
			
	/** Template to format toString() output */
	private static final String TO_STRING_TEMPLATE = "%s %s, %s";
	
	@Override
	public String toString() {
		return String.format(
				Employee.TO_STRING_TEMPLATE,
				this.getFirstName(), 
				this.getSecondName(), 
				this.getPosition());
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj == this) {
			return true;
		}
		
		if (!(obj instanceof Employee)) {
			return false;
		}
		
		Employee e = (Employee)obj;
		
		if (this.compareFirstName(e.getFirstName())
				&& this.compareSecondName(e.getSecondName())
				&& this.comparePosition(e.getPosition())
				&& this.compareDateOfBirth(e.getDateOfBirth())) {
			return true;
		} else {
			return false; 
		}
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getDateOfBirth() {
		return dateOfBirth;
	}

	public void setDateOfBirth(String dateOfBirth) {
		this.dateOfBirth = dateOfBirth;
	}

	public String getSecondName() {
		return secondName;
	}

	public void setSecondName(String secondName) {
		this.secondName = secondName;
	}

	public String getPosition() {
		return position;
	}

	public void setPosition(String position) {
		this.position = position;
	}
		
	/**
	 * Check first name for a match ignoring case
	 * @param firstName first name for checking 
	 * @return true if matches else false
	 */
	public boolean compareFirstName(String firstName) {
		return this.getFirstName().equalsIgnoreCase(firstName);
	}

	/**
	 * Check position for a match ignoring case
	 * @param position position for checking 
	 * @return true if matches else false
	 */
	public boolean comparePosition(String position) {
		return this.getPosition().equalsIgnoreCase(position);
	}
	
	/**
	 * Check second name for a match ignoring case
	 * @param secondName second name for checking 
	 * @return true if matches else false
	 */
	public boolean compareSecondName(String secondName) {
		return this.getSecondName().equalsIgnoreCase(secondName);
	}
	
	/**
	 * Check date of birth for a match ignoring case
	 * @param dateOfBirth date of birth for checking 
	 * @return true if matches else false
	 */
	public boolean compareDateOfBirth(String date) {
		return this.getDateOfBirth().equalsIgnoreCase(date);
	}

	public int getId() {
		return id;
	}

	protected void setId(int id) {
		this.id = id;
	}
	
	@Override
	public int hashCode() {
		return (31 * super.hashCode() + this.getId()); 		
	}
}